/**
 * 
 *  @project Air Traff Monitor
 * 
 *  @author M.Emre ATASEVER <m.emre.atas@gmail.com>
 *  @author M.Burak ALKAN <mburakalkan@gmail.com>
 *  @author H.Burak KARAMIK <bkaramik@gmail.com>
 *
 *	`Air Traffic Monitor' is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "netitem.h"

NetworkItem::NetworkItem(networkInfo *data, NetworkRootItem *parent) : NetmodelData<NetworkRootItem,NetworkItem>(parent)
{
	llcpackets	= 
	dupeivpackets	=
	channel		=
	turbocellnid	= 
	turbocellmode	= 
	turbocellsat	= 
	cloaked		= 
	beaconrate	= 
	octets		= 
	carrierset	=
	bsstimestamp	= 0;
	hasColor= false;
	bssid	= data->props[0].toString();
	setData(data);
}

NetworkItem::~NetworkItem()
{
	qDeleteAll(items);
	items.clear();
}

int NetworkItem::rowCount()
{
	return items.size();
}

ClientItem* NetworkItem::addClient(clientInfo *info)
{
	ClientItem *r	= new ClientItem(info,this);
	items.append(r);
	return r;

}

void *NetworkItem::getPointer(int field,NetworkItem *item,int *type,bool)
{
	*type	= 0;
	switch(field){
		case NETOPT_BSSID:
			*type	= 1;
			return &item->bssid;
		case NETOPT_TYPE:
			return &item->type;	
		case NETOPT_SSID:
			*type	= 1;
			return  &item->ssid;
		case NETOPT_CHANNEL:
			return &item->channel;
		case NETOPT_RANGEIP:
			*type	= 1;
			return &item->rangeip;
		case NETOPT_MAXRATE:
			*type = 3;
			return &item->maxrate;
		case NETOPT_WEP:
			return &item->wep;
		case NETOPT_BEACONINFO:
			*type	= 1;
			return &item->beaconinfo;
		case NETOPT_FIRSTTIME:
			*type	= 4;
			return &item->firsttime;
		case NETOPT_LASTTIME:
			*type	= 4;
			return &item->lasttime;
		case NETOPT_ATYPE:
			return &item->atype;
		case NETOPT_GPSFIXED:
			return &item->gpsfixed;
		case NETOPT_OCTETS:
			return &item->octets;
		case NETOPT_CLOAKED:
			return &item->cloaked;
		case NETOPT_BEACONRATE:
			return &item->beaconrate;
		case NETOPT_MANUFKEY:
			*type	= 1;
			return &item->manufkey;
		case NETOPT_MANUFSCORE:
			return &item->manufscore;
		case NETOPT_DATASIZE:
			*type	= 5;
			return &item->datasize;
		case NETOPT_CARRIERSET:
			return &item->carrierset;
		case NETOPT_MAXSEENRATE:
			return &item->maxseenrate;
		case NETOPT_ENCODINGSET:
			return &item->encodingset;
		case NETOPT_DECRYPTED:
			return &item->decrypted;
		case NETOPT_BSSTIMESTAMP:
			*type	= 7;
			return &item->bsstimestamp;
		case NETOPT_TURBOCELLNID:
			return &item->turbocellnid;
		case NETOPT_TURBOCELLMODE:
			return &item->turbocellmode;
		case NETOPT_TURBOCELLSAT:
			return &item->turbocellsat;
		case NETOPT_MAXLAT:
			*type	= 2;
			return &item->maxlat;
		case NETOPT_MAXLON:
			*type	= 2;
			return &item->maxlon;
		case NETOPT_MAXALT:
			*type	= 2;
			return &item->maxalt;
		case NETOPT_BESTLAT:
			*type	= 2;
			return &item->bestalt;
		case NETOPT_BESTLON:
			*type	= 2;
			return &item->bestlon;
		case NETOPT_BESTALT:
			*type	= 2;
			return &item->bestalt;
		case NETOPT_AGGLAT:
			*type	= 3;
			return &item->agglat;
		case NETOPT_AGGLON:
			*type	= 3;
			return &item->agglon;
		case NETOPT_AGGALT:
			*type	= 3;
			return &item->aggalt;
		case NETOPT_AGGPOINTS:
			*type	= 6;
			return &item->aggpoints;
		case NETOPT_MINLAT:
			*type	= 2;
			return &item->minlat;
		case NETOPT_MINLON:
			*type	= 2;
			return &item->minlon;
		case NETOPT_MINALT:
			*type = 2;
			return &item->minalt;
		case NETOPT_MINSPD:
			*type = 2;
			return &item->minspd;
		case NETOPT_MAXSPD:
			*type = 2;
			return &item->maxspd;
		case NETOPT_LLCPACKETS:
			return &item->llcpackets;
		case NETOPT_DATAPACKETS:
			return &item->datapackets;
		case NETOPT_CRYPTPACKETS:
			return &item->cryptpackets;
		case NETOPT_WEAKPACKETS:
			return &item->weakpackets;
		case NETOPT_DUPEIVPACKETS:
			return &item->dupeivpackets;
		case NETOPT_QUALITY:
			return &item->quality;	
		case NETOPT_SIGNAL:
			return &item->signal;
		case NETOPT_NOISE:
			return &item->noise;
		case NETOPT_BESTQUALITY:
			return &item->bestquality;
		case NETOPT_BESTSIGNAL:
			return &item->bestsignal;
		case NETOPT_BESTNOISE:
			return &item->bestnoise;
	}
	return 0;
}

ClientItem::ClientItem(clientInfo *info,NetworkItem *parent) : NetmodelData<NetworkItem,ClientItem>(parent)
{
	hasColor= false;
	parentbssid	= info->props[0].toString();
	setData(info);
}

int ClientItem::rowCount()
{
	return 0;
}

void *ClientItem::getPointer(int field,ClientItem *item,int *type,bool maptonet)
{
	*type	= 0;
	if(maptonet)
	{
		switch(field){
			case NETOPT_BSSID:
				*type	= 1;
				return &item->bssid;
			case NETOPT_TYPE:
				return &item->type;
			case NETOPT_FIRSTTIME:
				*type	= 4;
				return &item->firsttime;
			case NETOPT_LASTTIME:
				*type	= 4;
				return &item->lasttime;
			case NETOPT_MANUFKEY:
				*type	= 1;
				return &item->manufkey;
			case NETOPT_MANUFSCORE:
				return &item->manufscore;
			case NETOPT_DATAPACKETS:
				return &item->datapackets;
			case NETOPT_CRYPTPACKETS:
				return &item->cryptpackets;
			case NETOPT_WEAKPACKETS:
				return &item->weakpackets;
			case NETOPT_GPSFIXED:
				return &item->gpsfixed;
			case NETOPT_MINLAT:
				*type	= 2;
				return &item->minlat;
			case NETOPT_MINLON:
				*type	= 2;
				return &item->minlon;
			case NETOPT_MINALT:
				*type	= 2;
				return &item->minalt;
			case NETOPT_MINSPD:
				*type	= 2;
				return &item->minspd;
			case NETOPT_MAXLAT:
				*type	= 2;
				return &item->maxlat;
			case NETOPT_MAXLON:
				*type	= 2;
				return &item->maxlon;
			case NETOPT_MAXALT:
				*type	= 2;
				return &item->maxalt;
			case NETOPT_MAXSPD:
				*type	= 2;
				return &item->maxspd;
			case NETOPT_AGGLAT:
				*type	= 3;
				return &item->agglat;
			case NETOPT_AGGLON:
				*type	= 3;
				return &item->agglon;
			case NETOPT_AGGALT:
				*type	= 3;
				return &item->agglat;
			case NETOPT_AGGPOINTS:
				*type	= 6;
				return &item->aggpoints;
			case NETOPT_MAXRATE:
				*type	= 3;
				return &item->maxrate;
			case NETOPT_QUALITY:
				return &item->quality;
			case NETOPT_SIGNAL:
				return &item->signal;
			case NETOPT_NOISE:
				return &item->noise;
			case NETOPT_BESTQUALITY:
				return &item->bestquality;
			case NETOPT_BESTSIGNAL:
				return &item->bestsignal;
			case NETOPT_BESTNOISE:
				return &item->bestnoise;
			case NETOPT_BESTLAT:
				*type	= 2;
				return &item->bestlat;
			case NETOPT_BESTLON:
				*type	= 2;
				return &item->bestlon;
			case NETOPT_BESTALT:
				*type	= 2;
				return &item->bestalt;
			case NETOPT_ATYPE:
				return &item->atype;
			case NETOPT_RANGEIP:
				*type	= 1;
				return &item->rangeip;
			case NETOPT_DATASIZE:
				*type	= 5;
				return &item->datasize;
			case NETOPT_MAXSEENRATE:
				return &item->maxseenrate;
			case NETOPT_ENCODINGSET:
				return &item->encodingset;
			case NETOPT_DECRYPTED:
				return &item->decrypted;
			case NETOPT_WEP:
				return &item->wep;
			default:
				*type	= 8;
				return 0;
		}
	}
	else switch(field){
		case CLIOPT_BSSID:
			*type	= 1;
			return &item->parentbssid;
		case CLIOPT_MAC:
			*type	= 1;
			return &item->bssid;
		case CLIOPT_TYPE:
			return &item->type;
		case CLIOPT_FIRSTTIME:
			*type	= 4;
			return &item->firsttime;
		case CLIOPT_LASTTIME:
			*type	= 4;
			return &item->lasttime;
		case CLIOPT_MANUFKEY:
			*type	= 1;
			return &item->manufkey;
		case CLIOPT_MANUFSCORE:
			return &item->manufscore;
		case CLIOPT_DATAPACKETS:
			return &item->datapackets;
		case CLIOPT_CRYPTPACKETS:
			return &item->cryptpackets;
		case CLIOPT_WEAKPACKETS:
			return &item->weakpackets;
		case CLIOPT_GPSFIXED:
			return &item->gpsfixed;
		case CLIOPT_MINLAT:
			*type	= 2;
			return &item->minlat;
		case CLIOPT_MINLON:
			*type	= 2;
			return &item->minlon;
		case CLIOPT_MINALT:
			*type	= 2;
			return &item->minalt;
		case CLIOPT_MINSPD:
			*type	= 2;
			return &item->minspd;
		case CLIOPT_MAXLAT:
			*type	= 2;
			return &item->maxlat;
		case CLIOPT_MAXLON:
			*type	= 2;
			return &item->maxlon;
		case CLIOPT_MAXALT:
			*type	= 2;
			return &item->maxalt;
		case CLIOPT_MAXSPD:
			*type	= 2;
			return &item->maxspd;
		case CLIOPT_AGGLAT:
			*type	= 3;
			return &item->agglat;
		case CLIOPT_AGGLON:
			*type	= 3;
			return &item->agglon;
		case CLIOPT_AGGALT:
			*type	= 3;
			return &item->agglat;
		case CLIOPT_AGGPOINTS:
			*type	= 6;
			return &item->aggpoints;
		case CLIOPT_MAXRATE:
			*type	= 3;
			return &item->maxrate;
		case CLIOPT_QUALITY:
			return &item->quality;
		case CLIOPT_SIGNAL:
			return &item->signal;
		case CLIOPT_NOISE:
			return &item->noise;
		case CLIOPT_BESTQUALITY:
			return &item->bestquality;
		case CLIOPT_BESTSIGNAL:
			return &item->bestsignal;
		case CLIOPT_BESTNOISE:
			return &item->bestnoise;
		case CLIOPT_BESTLAT:
			*type	= 2;
			return &item->bestlat;
		case CLIOPT_BESTLON:
			*type	= 2;
			return &item->bestlon;
		case CLIOPT_BESTALT:
			*type	= 2;
			return &item->bestalt;
		case CLIOPT_ATYPE:
			return &item->atype;
		case CLIOPT_IP:
			*type	= 1;
			return &item->rangeip;
		case CLIOPT_DATASIZE:
			*type	= 5;
			return &item->datasize;
		case CLIOPT_MAXSEENRATE:
			return &item->maxseenrate;
		case CLIOPT_ENCODINGSET:
			return &item->encodingset;
		case CLIOPT_DECRYPTED:
			return &item->decrypted;
		case CLIOPT_WEP:
			return &item->wep;
	}
	return 0;
}
